import React from 'react';
import {Form, Select} from "antd";
import {DefaultOptionType} from "rc-select/lib/Select";

interface SelectEnhanceProps<T>{
    /**
     * 选择的字段的名字
     */
    name: keyof T,
    /**
     * 选择的字段的标签
     */
    label: string,
    /**
     * 渲染需要需要的选项值
     */
    option: DefaultOptionType[],
    /**
     * 选择框的值发生变化时的回调
     */
    onChange?: (value: string) => void

}

const SelectEnhance = <T, > (props: SelectEnhanceProps<T>) => {
    return (
        <Form.Item<T> label={props.label} name={props.name as any}>
            <Select
                onChange={props.onChange}
                placeholder={`请选择${props.label}`}
                allowClear
                options={props.option}
                loading={props.option.length === 0}
            />
        </Form.Item>
    );
};

export default SelectEnhance;